﻿/***************************************************************************
 //* Foxit Software Inc.
 //* Copyright(C) 2005-2012, all rights reserved.
 //*
 //* The following code is copyrighted and contains proprietary information
 /* and trade secrets of Foxit Software Inc.
 **************************************************************************
 */

/**
 * 简单的图片延迟加载
 */
define(function (require, exports, module) {
    var WebPDF = require('./WebPDF.js');
    WebPDF.ImgLazyLoad = function (url, bCache, readerApp, curPageView, callback, failedCallback) {
        var headers = {};
        var data = {};
        if(readerApp.getSessionId() != null){
            headers[readerApp.getSessionIdAuthHeader()] = readerApp.getSessionId();
        }
        $.ajax({
            url: url,
            cache: bCache,
            dataType: "text",
            data:data,
            contentType:"application/x-www-form-urlencoded",
            crossDomain:true,
            xhrFields: {
                withCredentials: true
            },
            headers: headers,
            ifModified: true,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                if ($.isFunction(failedCallback))
                    failedCallback(curPageView);
            },
            success: function (data, textStatus) {
                if ((data == WebPDF.ImageEngine.GetImageErrorCode.ERROR_PAGE_DISPLAY_LIMIT.toString()
                    || data == WebPDF.ImageEngine.GetImageErrorCode.ERROR_CREATE_IMG_FAILED.toString()
                    || data == WebPDF.ImageEngine.GetImageErrorCode.ERROR_INPROGRESS.toString())
                    && textStatus == "success")
                    callback(curPageView, data);
                else
                    callback(curPageView);
            }
        });
    };
    return WebPDF.ImgLazyLoad;
});